package com.bc.bcbuyerapihttp.controller;

import com.bc.bcapi.dao.T_User_buyer_infoMapper;
import com.bc.bcapi.service.T_Project_ceokycService;
import com.bc.bcapi.service.T_User_buyer_infoService;
import com.bc.bcbuyerapihttp.common.UserContext;
import com.bc.bcmodel.BuyerUserInfo;
import com.bc.bcmodel.domain.T_Project_ceokycModel;
import com.bc.bcmodel.domain.T_User_buyer_infoModel;
import com.bc.bcmodel.req.UserSetHeadFigureReq;
import com.bc.commonentity.common.JsonResult;
import com.bc.commonentity.enums.HttpReturnRnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Name BuyerController
 * @Description 买家信息
 * @Author douhaichao
 * @Date 2018/8/27 16:44
 * @Version 1.0
 **/
@Api("买家管理")
@RestController
@RequestMapping("buyer")
public class BuyerController {

    @Autowired
    T_Project_ceokycService t_project_ceokycService;
    @Autowired
    T_User_buyer_infoService t_user_buyer_infoService;

    @ApiOperation("获取当前用户的CEO KYC信息,如果auth_status=0时才会显示保存草稿")
    @RequestMapping(value = "getceokyc", method = RequestMethod.GET)
    public JsonResult getCeoKyc() {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        return t_user_buyer_infoService.getCeoKyc(userInfo.getUser_id());
    }

    @ApiOperation("设置当前用户的CEO KYC信息;{auth_status,0 保存草稿 1提交审核}")
    @RequestMapping(value = "setceokyc", method = RequestMethod.POST)
    public JsonResult setCeoKyc(@RequestBody T_User_buyer_infoModel req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_user_buyer_infoService.setCeoKyc(req, userInfo.getUser_id());
    }

    @ApiOperation("头象变更")
    @RequestMapping(value = "setheadfigure", method = RequestMethod.POST)
    public JsonResult setHeadFigure(@RequestBody UserSetHeadFigureReq req) {
        BuyerUserInfo userInfo = UserContext.getCurrentContext().getLoginInfo();
        if (userInfo == null) {
            return new JsonResult(HttpReturnRnums.NOT_LOGIN);
        }
        req.setUser_id(userInfo.getUser_id());
        return t_user_buyer_infoService.setHeadFigure(req);
    }
}
